package concurrencyPractice.chapter03;

/**
 * @author xinya
 * @version 1.0
 * @project javacore
 * @description 程序3-1 可见性
 * @date 2023/12/26 17:24:43
 */
public class NoVisibility {
    private static int number;
    private static boolean ready;

    private static class ReaderThread extends Thread {
        public void run () {
            while (!ready) {
                Thread.yield();
            }
            System.out.println(number);
        }
    }

    public static void main(String[] args) {
        new ReaderThread().start();

        number = 42;
        ready = true;
    }
}
